home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / A.D. Software / OOFILE / Buildable, limited OOFILE / samples / ooftst02.inc < prev    next >
Text File  |  1996-03-31  |  2KB  |  91 lines

  1. // included in ooftst2, 3, 4, 6, 9 & 15
  2.  
  3. DECLARE_REF(dbPatients)
  4. DECLARE_SET(dbVisits)
  5.  
  6. DECLARE_CLASS(dbPatients)
  7.     dbChar        LastName, Othernames;
  8.     dbVisitsSet    Visits;
  9.     dbLong        PatientNo;
  10.     dbLong        Salary;
  11.  
  12.     dbPatients() :
  13.                 LastName(40, "Last Name", kIndexed),
  14.                 Othernames(80, "Other names", kIndexed),
  15.                 PatientNo("PatientNo", kIndexNoDups),
  16.                 Salary("Salary", kIndexed)
  17.     {
  18.         Visits.joinField(PatientNo);
  19.     };
  20.     
  21. // my own data entry procedures
  22.     void Add(const char *lname, const char *oname, const long salary);
  23.     void AddVisit(const char* visitDate, const char* why);
  24.     void AddTestData();
  25.     
  26. };
  27.  
  28.  
  29. DECLARE_CLASS(dbVisits)
  30.     dbPatientsRef    Patient;
  31.     dbLong        PatientNo;
  32.     dbDate        VisitDate;
  33.     dbChar        Why;
  34.     dbVisits() : 
  35.                 PatientNo("PatientNo", kIndexed),
  36.                 VisitDate("VisitDate", kIndexed),
  37.                 Why(200, "Reason for Visit", kIndexCompress)
  38.     {
  39.         Patient.joinField(PatientNo);
  40.     };
  41. };
  42.  
  43.  
  44. void dbPatients::Add(const char *lname, const char *oname, const long salary)
  45. {
  46.     newRecord();
  47.     LastName = lname;
  48.     Othernames = oname;
  49.     Salary = salary;
  50.     PatientNo = sequenceNumber();
  51.     saveRecord();
  52. }
  53.  
  54.  
  55. void dbPatients::AddVisit(const char* visitDate, const char* why)
  56. {
  57.     Visits->newRecord();
  58.     Visits->VisitDate = visitDate;
  59.     Visits->Why = why;
  60. }
  61.  
  62.  
  63. void dbPatients::AddTestData()
  64. {
  65. // yes, if using SmartHeap debugging the following can take long enough to make folks wonder
  66. // there are a *lot* of places where OOFILE calls SmartHeap to check memory
  67.         cout << "Generating new test records..." << flush;
  68.         Add("Smith", "John", 20000);
  69.             AddVisit("1/10/1994", "Sore Knee");
  70.             AddVisit("14/10/1994", "Measles");
  71.         saveRecord();
  72.         
  73.         Add("DENT", "Trissa", 99999);
  74.             AddVisit("23-11-1994", "Flu");
  75.         saveRecord();
  76.  
  77.         Add("Dent", "Andy", 50000);
  78.             AddVisit("4.10.1994", "Flu");
  79.         saveRecord();
  80.  
  81.         Add("Taylor", "Ken", 75000);
  82.         cout << endl << endl;
  83. }
  84.  
  85.  
  86. // global variables that define the database using the above classes
  87.  
  88.     dbConnect_ctree    theDB;
  89.     dbPatients     Patients;
  90.     dbVisits    Visits;
  91.     dbRelationship PatientVisits(Patients.Visits, Visits.Patient);